package MapReduce.Demo10_TemperatureByYear;

import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Partitioner;


/**
 * @Author lixinlei
 * @Date 2023/3/22 8:43
 */
public class TemperatureByYearPartition extends Partitioner<Text, Text> {

    @Override
    public int getPartition(Text key, Text value, int numPartitions) {

        //把年份转成int类型
        int year = Integer.parseInt(key.toString());

        if(year >= 1900 && year < 1930){
            return 0;
        }else if(year >= 1930 && year < 1960){
            return 1;
        }else if(year >= 1960 && year < 1990){
            return 2;
        }else{
            return 3;
        }
    }
}
